<template>
<div>
  <el-form ref="form" :model="myOrder" label-width="150px" style="text-align: center;width: 800px"  label-position="left">
    <el-form-item label='房间号'>
      <el-input v-model="myOrder.rid"></el-input>
    </el-form-item>
    <el-form-item label='顾客身份证号' :rules="[
      { required: true, message: '年龄不能为空'},
      { type: 'number', message: '年龄必须为数字值'}
    ]">
      <el-input v-model="myOrder.cid" ></el-input>
    </el-form-item>
    <el-form-item label='同住人id'>
      <el-input v-model="myOrder.cidrest" ></el-input>
    </el-form-item>
    <el-form-item label="活动区域">
      <el-select v-model="myOrder.daysOrHours" placeholder="选择天数">
        <span v-for="index in 14">
              <el-option  :value="index" >{{index}}天 {{daten(endTime + index*86400000)}} </el-option>
        </span>

      </el-select>
    </el-form-item>
    <el-form-item label="备注">
      <el-input type="textarea" v-model="myOrder.remark"></el-input>
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="onSubmit">创建订单</el-button>
</div>
</template>

<script>
import instance from "@/untils";

export default {
  data() {
    return {
      myOrder:{
        rid:this.ridNum
      },
      endTime:Date.parse(new Date())
    }
  },
  methods: {
    onSubmit() {
      let object = new Object();
      let key=localStorage.getItem("key");
      object.key=key;
      object.rid=this.myOrder.rid;
      object.cid=this.myOrder.cid;
      if(this.myOrder.cidrest!=null){
       object.cidrest=this.myOrder.cidrest;
      }
      if(this.myOrder.remark!=null){
       object.remark=this.myOrder.remark;
      }
      object.daysOrHours=this.myOrder.daysOrHours;

      instance.post('/order/create',object).then(res=>{
        if(res.data.status==200){
          this.$message({
            message:'订购成功',
            type:"success"
          });
        }
        else{
          this.$message({
            message:res.data.msg,
            type:"warning"
          });
        }
      })
    },
    daten(timestamp){
      let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      let Y = date.getFullYear() + '-';
      let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
      let D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
      return Y+M+D;
    }
  },
  computed:{

  },
  props:['ridNum']
}
</script>

<style scoped>

</style>